package org.example.infrastructure.order.gatewayimpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.example.domain.order.entity.OrderEntity;
import org.example.domain.order.gateway.OrderGateway;
import org.example.infrastructure.common.base.BaseGatewayImpl;
import org.example.infrastructure.order.convertor.OrderConvertor;
import org.example.infrastructure.order.gatewayimpl.database.dataobject.OrderDO;
import org.example.infrastructure.order.gatewayimpl.database.mapper.OrderMapper;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class OrderGatewayImpl extends BaseGatewayImpl<Long, OrderEntity, OrderDO, OrderMapper, OrderConvertor> implements OrderGateway {

    @Resource
    private OrderMapper orderMapper;

    @Override
    public OrderEntity getByOrderNo(String orderNo) {
        LambdaQueryWrapper<OrderDO> queryWrapper = Wrappers.lambdaQuery(OrderDO.class)
                .eq(OrderDO::getOrderNo, orderNo);
        OrderDO orderDO = orderMapper.selectOne(queryWrapper);
        return convertor.toEntity(orderDO);
    }
}
